export default ({ app }, inject) => {
  // url : string, 服务器端url
  // data: Object, 请求的数据
  // addInfo: Object, 请求的head信息-
  // isNotify: bool, 是否在右上角显示提示信息，默认'yes', 不显示传'no'
  inject("postService", async function(url, data, addInfo, isNotify) {
    // 客户端请求，需要使用前缀/api/代理
    // console.log('window from remoteserver, ', app, inject, process.env) interface/forward
    var postData = data;
    if (!process.server) {
      //
    }
    if (
      url.indexOf("python/") > -1 ||
      url.indexOf("Guo/") > -1 ||
      url.indexOf("SC/") > -1 ||
      url.indexOf("Prod/") > -1 ||
      url.indexOf("fileTian/") > -1 ||
      url.indexOf("fileLoad/") > -1 ||
      url.indexOf("themApi/") > -1 ||
      url.indexOf("api/") > -1
    ) {
      if (url.indexOf("python/") > -1) {
        url = "/python" + url;
        postData = {
          sender: "web",
          body: JSON.stringify(postData)
        };
      }
    } else {
      url = "/api/" + url;
      if (postData.version != undefined) {
        postData.version = postData.version + "";
      }
    }
    try {
      const result = await app.$axios.$post(url, postData, addInfo);
      if (!process.server && (!isNotify || isNotify !== "no")) {
      }
      if (
        url.indexOf("python/") > -1 &&
        url.indexOf("/mppHsm/exportTable") == -1
      ) {
        return result.data;
      }
      return result;
    } catch (e) {
      if (process.server) return;
      this.$notify.error({
        title: "系统信息",
        message:
          process.env.NODE_ENV === "production"
            ? "通讯出错了，请稍后再试"
            : e.message,
        showClose: true
      });
      return {
        status: "sysError",
        code: e.response && e.response.status ? e.response.status : "401"
      };
    }
  });

  inject("getService", async function(url, data, addInfo, isNotify) {
    if (!process.server) {
    }
    if (url.indexOf("Guo/") > -1 || url.indexOf("SC/") > -1) {
    } else {
      url = "/api/" + url;
    }
    try {
      const result = await app.$axios.$get(url, addInfo);
      if (!process.server && (!isNotify || isNotify !== "no")) {
      }
      return result;
    } catch (e) {
      if (process.server) return;
      this.$notify.error({
        title: "系统信息",
        message:
          process.env.NODE_ENV === "production"
            ? "通讯出错了，请稍后再试"
            : e.message,
        showClose: false
      });
    }
  });
};
